﻿using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace wnet.admin.Models
{

    public class CustomContractResolver : DefaultContractResolver
    {
        protected override string ResolvePropertyName(string propertyName)
        {
            try
            {
                // 实现自定义的属性名称转换规则
                //return propertyName.Replace("zh", "_zh");

                string hzstr = propertyName.Substring(propertyName.Length - 2);


                if (hzstr.Contains("zh"))
                {
                    if (propertyName.ToLower() == "Destextzh".ToLower())
                    {
                        return propertyName.ToLower() + "_zh";
                    }
                    return (propertyName.Substring(0, propertyName.Length - 2) + "_zh").ToLower();
                }
                else if (hzstr.Contains("en"))
                {
                    if (propertyName.ToLower() == "children".ToLower()) 
                    {
                        return propertyName.ToLower();
                    }
                    return (propertyName.Substring(0, propertyName.Length - 2) + "_en").ToLower();
                }
                else if (hzstr.Contains("tc"))
                {
                    return (propertyName.Substring(0, propertyName.Length - 2) + "_tc").ToLower();
                }
                else if (hzstr.Contains("pt"))
                {
                    return (propertyName.Substring(0, propertyName.Length - 2) + "_pt").ToLower();
                }
                return base.ResolvePropertyName(propertyName).ToLower();
            }
            catch (Exception ex)
            {
                return base.ResolvePropertyName(propertyName).ToLower();
            }

        }
    }


}